package com.thyme.system.rest;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.thyme.common.base.ApiResponse;
import com.thyme.system.dao.WytShipmentDao;
import com.thyme.system.entity.WytShipment;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/shipment")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class ShipmentRestController {
    private final WytShipmentDao dao;

    @GetMapping("/list")
    public ApiResponse getUserInfo(@RequestParam("page") int page,
                                   @RequestParam("page_size") int pageSize) {
        JSONObject jsonObject = new JSONObject();
        List<WytShipment> userList = new ArrayList<>(16);
        IPage<WytShipment> sysUserList = dao.getAll(new Page(page, pageSize));
        if (sysUserList.getRecords() != null && sysUserList.getRecords().size() > 0) {
            userList = sysUserList.getRecords();
        }
        jsonObject.put("total", sysUserList.getTotal());
        jsonObject.put("page", sysUserList.getCurrent());
        jsonObject.put("page_size", sysUserList.getSize());
        jsonObject.put("sysUserList", userList);
        return ApiResponse.ofSuccess(jsonObject);
    }

}
